extern crate serialize;
extern crate toml;
-use core::errors::{CargoResult,CargoError,ToResult,Described,Other};
+use core::errors::{CargoResult,CargoError,ToResult};
use serialize::{Encodable,Encoder};
use std::{io,fmt};
pub fn get_config(pwd: Path, key: &str) -> CargoResult<ConfigValue> {
find_in_tree(&pwd, |file| extract_config(file, key)).to_result(|_|
- CargoError::internal(Described(format!("Config key not found: {}", key))))
+ CargoError::described(format!("Config key not found: {}", key)))
}
pub fn all_configs(pwd: Path) -> CargoResult<collections::HashMap<~str, ConfigValue>> {
loop {
let possible = current.join(".cargo").join("config");
if possible.exists() {
- let file = try!(io::fs::File::open(&possible).to_result(|_| CargoError::internal(Other)));
+ let file = try!(io::fs::File::open(&possible).to_result(|_| CargoError::other()));
match walk(file) {
Ok(res) => return Ok(res),
_ => ()
if !current.pop() { break; }
}
- Err(CargoError::internal(Other))
+ Err(CargoError::other())
}
fn walk_tree(pwd: &Path, walk: |io::fs::File| -> CargoResult<()>) -> CargoResult<()> {
loop {
let possible = current.join(".cargo").join("config");
if possible.exists() {
- let file = try!(io::fs::File::open(&possible).to_result(|_| CargoError::internal(Other)));
+ let file = try!(io::fs::File::open(&possible).to_result(|_| CargoError::other()));
match walk(file) {
Err(_) => err = false,
_ => ()
}
}
- if err { return Err(CargoError::internal(Other)); }
+ if err { return Err(CargoError::other()); }
if !current.pop() { break; }
}
}
fn extract_config(file: io::fs::File, key: &str) -> CargoResult<ConfigValue> {
- let path = try!(file.path().as_str().to_result(|_| CargoError::internal(Other))).to_owned();
+ let path = try!(file.path().as_str().to_result(|_| CargoError::other())).to_owned();
let mut buf = io::BufferedReader::new(file);
- let root = try!(toml::parse_from_buffer(&mut buf).to_result(|_| CargoError::internal(Other)));
- let val = try!(root.lookup(key).to_result(|_| CargoError::internal(Other)));
+ let root = try!(toml::parse_from_buffer(&mut buf).to_result(|_| CargoError::other()));
+ let val = try!(root.lookup(key).to_result(|_| CargoError::other()));
let v = match val {
&toml::String(ref val) => String(val.to_owned()),
&toml::Array(ref val) => List(val.iter().map(|s: &toml::Value| s.to_str()).collect()),
- _ => return Err(CargoError::internal(Other))
+ _ => return Err(CargoError::other())
};
Ok(ConfigValue{ value: v, path: vec!(path) })
}
fn extract_all_configs(file: io::fs::File, map: &mut collections::HashMap<~str, ConfigValue>) -> CargoResult<()> {
- let path = try!(file.path().as_str().to_result(|_| CargoError::internal(Other))).to_owned();
+ let path = try!(file.path().as_str().to_result(|_| CargoError::other())).to_owned();
let mut buf = io::BufferedReader::new(file);
- let root = try!(toml::parse_from_buffer(&mut buf).to_result(|_| CargoError::internal(Other)));
- let table = try!(root.get_table().to_result(|_| CargoError::internal(Other)));
+ let root = try!(toml::parse_from_buffer(&mut buf).to_result(|_| CargoError::other()));
+ let table = try!(root.get_table().to_result(|_| CargoError::other()));
for (key, value) in table.iter() {
match value {
fn merge_array(existing: &mut ConfigValue, val: &[toml::Value], path: &str) -> CargoResult<()> {
match existing.value {
- String(_) => return Err(CargoError::internal(Other)),
+ String(_) => return Err(CargoError::other()),
List(ref mut list) => {
let new_list: Vec<CargoResult<~str>> = val.iter().map(|s: &toml::Value| toml_string(s)).collect();
if new_list.iter().any(|v| v.is_err()) {
- return Err(CargoError::internal(Other));
+ return Err(CargoError::other());
} else {
let new_list: Vec<~str> = new_list.move_iter().map(|v| v.unwrap()).collect();
list.push_all(new_list.as_slice());
fn toml_string(val: &toml::Value) -> CargoResult<~str> {
match val {
&toml::String(ref str) => Ok(str.to_owned()),
- _ => Err(CargoError::internal(Other))
+ _ => Err(CargoError::other())
}
}
use std::io;
use std::io::process::{Process,ProcessConfig,ProcessOutput,InheritFd};
use collections::HashMap;
-use core::errors::{ToResult,CargoResult,CargoError,Described};
+use core::errors::{ToResult,CargoResult,CargoError};
#[deriving(Clone,Eq)]
pub struct ProcessBuilder {
config.cwd = Some(&self.cwd);
let os_path = try!(os::getenv("PATH").to_result(|_|
- CargoError::internal(Described("Could not find the PATH environment variable".to_owned()))));
+ CargoError::described("Could not find the PATH environment variable")));
let path = os_path + PATH_SEP + self.path.connect(PATH_SEP);
config.env = Some(path.as_slice());
Process::configure(config).map(|mut ok| ok.wait_with_output()).to_result(|_|
- CargoError::internal(Described("Could not spawn process".to_owned())))
+ CargoError::described("Could not spawn process"))
}
fn build_config<'a>(&'a self) -> io::IoResult<ProcessConfig<'a>> {